/**
 * 沪深股通持股管理初始化
 */
var Hsgt = {
    id: "HsgtTable",	//表格id
    seItem: null,		//选中的条目
    table: null,
    layerIndex: -1
};

/**
 * 初始化表格的列
 */
Hsgt.initColumn = function () {
    return [
        {field: 'selectItem', radio: true},
        	{title: '机构名称', field: 'gSalesName', visible: true, align: 'center', valign: 'middle'},
            {title: '代码', field: 'gScode', visible: true, align: 'center', valign: 'middle'},
            {title: '名称', field: 'gName', visible: true, align: 'center', valign: 'middle'},
            {title: '所属行业', field: 'gOwerBk', visible: true, align: 'center', valign: 'middle'},
            {title: '最新价', field: 'gPrice', visible: true, align: 'center', valign: 'middle'},
            {title: '区间涨跌幅(%)', field: 'gJqZdf', visible: true, align: 'center', valign: 'middle'},
            {title: '资金关注排行', field: 'gZjgzRank', visible: true, align: 'center', valign: 'middle'},
            {title: '买入额(万)', field: 'gBmoney', visible: true, align: 'center', valign: 'middle'},
            {title: '卖出额(万)', field: 'gSmoney', visible: true, align: 'center', valign: 'middle'},
            {title: '买卖净额(万)', field: 'gPbuy', visible: true, align: 'center', valign: 'middle'},
            {title: '主力成本', field: 'ZLCB', visible: true, align: 'center', valign: 'middle'},
            {title: '控盘度', field: 'JGCYDType', visible: true, align: 'center', valign: 'middle'},
            {title: '市盈率', field: 'PERation', visible: true, align: 'center', valign: 'middle'},
            {title: '总市值(亿)', field: 'gZsz', visible: true, align: 'center', valign: 'middle'},
            {title: '操作日期', field: 'gTdate', visible: true, align: 'center', valign: 'middle'},
    ];
};

/**
 * 检查是否选中
 */
Hsgt.check = function () {
    var selected = $('#' + this.id).bootstrapTable('getSelections');
    if(selected.length == 0){
        Feng.info("请先选中表格中的某一记录！");
        return false;
    }else{
        Hsgt.seItem = selected[0];
        return true;
    }
};

/**
 * 点击添加沪深股通持股
 */
Hsgt.openAddHsgt = function () {
    var index = layer.open({
        type: 2,
        title: '添加沪深股通持股',
        area: ['800px', '420px'], //宽高
        fix: false, //不固定
        maxmin: true,
        content: Feng.ctxPath + '/hsgt/hsgt_add'
    });
    this.layerIndex = index;
};

/**
 * 打开查看沪深股通持股详情
 */
Hsgt.openHsgtDetail = function () {
    if (this.check()) {
        var index = layer.open({
            type: 2,
            title: '沪深股通持股详情',
            area: ['800px', '420px'], //宽高
            fix: false, //不固定
            maxmin: true,
            content: Feng.ctxPath + '/hsgt/hsgt_update/' + Hsgt.seItem.id
        });
        this.layerIndex = index;
    }
};

/**
 * 删除沪深股通持股
 */
Hsgt.delete = function () {
    if (this.check()) {
        var ajax = new $ax(Feng.ctxPath + "/hsgt/delete", function (data) {
            Feng.success("删除成功!");
            Hsgt.table.refresh();
        }, function (data) {
            Feng.error("删除失败!" + data.responseJSON.message + "!");
        });
        ajax.set("hsgtId",this.seItem.id);
        ajax.start();
    }
};

/**
 * 查询沪深股通持股列表
 */
Hsgt.search = function () {
    var queryData = {};
    queryData['date'] = $("#date").val();
    queryData['hsgtType'] = $("#hsgtType").val();
    queryData['dm'] = $("#dm").val();
    Hsgt.table.refresh({query: queryData});
};

$(function () {
    var defaultColunms = Hsgt.initColumn();
    var table = new BSTable(Hsgt.id, "/hsgt/list", defaultColunms);
    table.setPaginationType("server");
    Hsgt.table = table.init();
});
